#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
  struct ListNode {
      int val;
     struct ListNode *next;
 };
 
struct ListNode* deleteDuplicates(struct ListNode* head) {
    struct ListNode* a = head;
    struct ListNode* b = (struct ListNode*)malloc(sizeof(struct ListNode));
    b->val = 0;
    b->next = a;
    if (head == NULL)
        return head;
    if (head->next == NULL)
        return head;
    else {
        while (a->next) {
            if (a->val < a->next->val) {
                a = a->next;
            }
            else {
                struct ListNode* c = a->next;
                a->next = c->next;
                free(c);
                c = NULL;
            }
        }
        a = b->next;
        return a;
    }

}
void Init(struct ListNode** p,int x) {
        
        struct ListNode* h = (struct ListNode*)malloc(sizeof(struct ListNode));
        h->val = x;
        h->next = NULL;
        if (*p == NULL)
            *p = h;
        else
        {
            struct ListNode* new = *p;
            while (new->next) {
                new = new->next;
            }
            new->next = h;
        }

}
void print(struct ListNode* p) {
    if (p == NULL) {
        printf("");
    }
    else {
        while (p) {
            printf("%d ", p->val);
            p = p->next;
        }
    }
}
int main() {
    struct ListNode* l = NULL;
    Init(&l,1);
    Init(&l, 1);
    Init(&l, 2);
    Init(&l, 2);
    Init(&l, 3);
    l = deleteDuplicates(l);
    print(l);
}